package com.lagou.server;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerInitClose {
    private ServerSocket ss;
    private Socket s;
    private ObjectInputStream ois;
    private ObjectOutputStream oos;
    //服务器初始化
    public void serverInit() throws IOException {
        //1.创建ServerSocket类型对象提供端口号
         ss = new ServerSocket(8080);
        System.out.println("等待客户端的连接请求...");
         s = ss.accept();
        System.out.println("客户端连接成功！");
         ois = new ObjectInputStream(s.getInputStream());
         oos = new ObjectOutputStream(s.getOutputStream());
        System.out.println("服务器初始化成功！");
    }
    //自定义成员方法实现服务器关闭
    public void serverClose() throws IOException {
        oos.close();
        ois.close();
        s.close();
        ss.close();
        System.out.println("服务器成功关闭！");
    }
    public ObjectInputStream getOis() {
        return ois;
    }

    public ObjectOutputStream getOos() {
        return oos;
    }
}
